<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>
<html>
<head>
    <title>订单管理 - 花店管理系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-4">
        <h2>订单管理</h2>
        <div class="mb-3">
            <a href="${pageContext.request.contextPath}/flower" class="btn btn-secondary">返回商品管理</a>
        </div>
        
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>订单号</th>
                        <th>用户</th>
                        <th>金额</th>
                        <th>状态</th>
                        <th>下单时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${orders}" var="order">
                        <tr>
                            <td>${order.id}</td>
                            <td>${order.username}</td>
                            <td>￥${order.totalAmount}</td>
                            <td>
                                <span class="badge ${order.status == 'pending' ? 'bg-warning' : 
                                                   order.status == 'paid' ? 'bg-info' :
                                                   order.status == 'shipped' ? 'bg-primary' :
                                                   order.status == 'completed' ? 'bg-success' : 'bg-danger'}">
                                    ${order.status == 'pending' ? '待付款' :
                                      order.status == 'paid' ? '已付款' :
                                      order.status == 'shipped' ? '已发货' :
                                      order.status == 'completed' ? '已完成' : '已取消'}
                                </span>
                            </td>
                            <td><fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                            <td>
                                <c:if test="${order.status == 'paid'}">
                                    <button class="btn btn-sm btn-primary" onclick="updateStatus(${order.id}, 'shipped')">发货</button>
                                </c:if>
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/js/bootstrap.bundle.min.js"></script>
    <script>
        function updateStatus(orderId, status) {
            if (!confirm('确定要更新订单状态吗？')) return;
            
            $.post("${pageContext.request.contextPath}/flower/order/status", {
                orderId: orderId,
                status: status
            }, function(response) {
                if (response.success) {
                    location.reload();
                } else {
                    alert(response.message || "操作失败，请重试");
                }
            });
        }
    </script>
</body>
</html> 